<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
    	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>箱码查询</title>
	    <link rel="stylesheet" href="css/AllStyle.css" />
	    <link rel="stylesheet" href="css/iconfont.css" />
	    <script type="text/javascript" src="js/common.js" ></script>
	    <script type="text/javascript" src="js/data.js" ></script>
	    <script type="text/javascript" src="js/tmpl.js" ></script>
	  </head>
	<body>
		<!-- 页头 -->
	    <section>
		    <script type="text/javascript">
		        AllPageHeader();
		    </script>
	    </section>
	    
	     <!-- 页面  -->
	    <section class="AllContent" style="background-color: #fff;padding-bottom:0px;">
	    	<div id="stocklist">
	    		<!-- 查询输入框 -->
				<div class="QueryInput">
					<ul>
						<li><input type="tetx" id="query"
	                       onkeypress="if (event.keyCode == 13) {
	                                                   proccessTextArea();
	                                                   return false;
	                                               }"
	                                       placeholder="输入产品编号"/></li>
						<li><button type="button" onclick="proccessTextArea();">查询</button></li>
					</ul>
				</div>
				
				<!-- 信息 -->
				<div class="StockNav" style="text-align:center;">
					<b>箱码商品列表</b>
				</div>
				<div id="itemHit">

        </div>
				<p id="BlurbLoading" style="background: #fff;overflow: hidden;margin-top:10px;display: none;"><img width="100px;" style="display:block;margin:30px auto;" src="images/loading5.gif"></p>
				
	    	</div>
	    </section>
	</body>
	<script type="text/javascript" src="js/jquery.min.js" ></script>
	<script type="text/javascript" src="js/mui.min.js" ></script>
	<script type="text/javascript">
	    mui.init();
		$('.AllHeader li:eq(1)').text('箱码查询');
		$('.AllHeader li:eq(2)').html('<img style="width:28px" src="images/Scan.png">')
		
		mui.plusReady(function(){
		    //扫描器
			document.getElementById('Scanner').addEventListener('tap', function() {
			  mui.openWindow({
			    url: 'Scanner.html?etk=8', 
			    id:'Scanner.html'
			  });
			});
		});
		//添加refresh自定义事件监听
		window.addEventListener('package_query',function(){
			var id = event.detail.id;
			$('#query').val(id);
			proccessTextArea();
		});
		
		$(function () {
			if (!empty(getCookie("itemcode"))) {
	            $("#query").val(getCookie("itemcode"));
	            proccessTextArea();
	        }
	        $("#query").focus();
        });


        function proccessTextArea() {
            var q = getItemNo($("#query").val());
            //console.log(q);
            $("#query").val(q);
            if (empty(q)) {
                alertMessage("标签编号不能为空！");
            } else {
	        	$('#BlurbLoading').show();
                $.ajax({//一个Ajax过程
                    type: "post", //以post方式与后台沟通
                    url: getServerUrl() + "/Open/Comtag/package_query",
                    dataType: 'json', //从php返回的值以 JSON方式 解释
                    data: 'item_no=' + q+'&access_token='+getToken(),
                    success: function (json) {//如果调用php成功
                    	$('#BlurbLoading').hide(300);
                    	$("#query").val(q);
                        if (json.result == "1") {
                            var html = "";
                            if(!empty(json.tag)) {
                                for (var i = 0; i < json.tag.length; i++) {
									html = html +'<div class="StockNav">'
												+'<ul style="padding:0;color:red;">'
												+'<li>标签编号</li><li style="width:66%;">'+json.tag[i].item_no+'</li>'
												+'</ul>'
			            			            +'<ul style="padding:0;">'
												+'<li>产品名称</li><li style="width:66%;">'+json.tag[i].pname+'</li>'
												+'</ul>'
			            			            +'<ul style="padding:0;">'
												+'<li>产品批次</li><li style="width:66%;">'+json.tag[i].lot_no+'</li>'
												+'</ul>'
												+'</div>';
                                }
                            }
                            $("#itemHit").html(html);
                            $(".StockNav b").html("箱码商品列表<span>（"+json.pkg_num+"）</span>");
                            /* 高度设置  */
							var WinH = $(window).height();
							var CrH = $('.ContainerRight').height();
							var ClH = $('.ContainerLeft').height();
							if(CrH>ClH && CrH>WinH){
								$('.ContainerLeft').height(CrH);
							}else{
								$('.ContainerLeft').height(ClH+20);
							}
                        } else {
                    		$("#query").val("");
                        	$('#BlurbLoading').hide(300);
                            alertMessage("查询数据异常:[" + json.error_description + "]");
                        }
                    }
                });
            }
        }

        function onDeviceReady() {
            document.addEventListener("backbutton", onBackKeyDown, false);
        }
        function onBackKeyDown() {
            openUrl("supper.html");
        }
        
	</script>
</html>
